/**
 * @file detail.tsx
 * @description 待配送详情
 */
import React, {useRef, useState} from 'react';
import {
  Box,
  FlatList,
  Heading,
  Avatar,
  HStack,
  VStack,
  Text,
  Spacer,
  Center,
  Button,
  ScrollView,
} from 'native-base';
import {useMount} from 'ahooks';
import {Camera} from 'react-native-camera-kit';
import {useIsFocused} from '@react-navigation/native';

const ScanScreen: React.FC<ComponentProp> = ({navigation, route}) => {
  /******变量******/
  const routeParams: any = route?.params;

  const isFocused = useIsFocused();

  /******生命周期******/
  useMount(() => {

  });

  /******方法******/

  // 扫码成功
  const handleBarcodeScan = (e: any) => {
    console.log('扫描结果' + e.nativeEvent.codeStringValue);
    navigation?.navigate('ScanDetailScreen', {
      scanCode: e.nativeEvent.codeStringValue,
      productionInfo:routeParams.productionInfo,
    });
  };

  return (
    <Box bg="gray.100" borderRadius="md" w="100%" h="100%">
      <Box pt="-100">
        {isFocused ? (
          <Camera
            style={{width: '100%', height: '100%', marginTop: '0'}}
            scanBarcode={true}
            onReadCode={handleBarcodeScan}
            showFrame={true}
            laserColor="red"
            frameColor="white"
          />
        ) : null}
      </Box>
      <HStack
        w="100%"
        h="20"
        justifyContent="space-between"
        px="10"
        bg="white"
        position="absolute"
        bottom="0"
        alignItems="center">
        <Button
          isLoadingText="跳转中..."
          w="40%"
          bg="#4F94F9"
          _pressed={{bg: '#4F94F9'}}
          onPress={() => {
            navigation?.navigate('ScanDetailScreen', {
              scanCode: '',
              productionInfo:routeParams.productionInfo,
            });
          }}>
          输入pk码
        </Button>
        <Button
          isLoadingText="返回中..."
          w="40%"
          bg="#4F94F9"
          _pressed={{bg: '#4F94F9'}}
          onPress={() => {
            navigation?.goBack();
          }}>
          返回
        </Button>
      </HStack>
    </Box>
  );
};

export default ScanScreen;
